package com.societyGames.asteroidExercises
{
	public class FunctionCallExpression implements INumberExpression
	{
		public static var x:Number;
		public static var y:Number;
		public static var z:Number;
		
		private var _functionCall:String;
		
		public function FunctionCallExpression(xml:XML)
		{
			if (!"value" in xml)
			{
				throw new ArgumentError("Xml missing required attribute \"value\".");
			}
			this._functionCall = xml.@value;
		}
		
		public function toString():String
		{
			if (this._functionCall != null)
			{
				return _functionCall + "()";
			}
			return "";
		}
		
		//INumberExpression-->
		public function evaluate():Number
		{
			switch (_functionCall)
			{
				case "getX":
					return FunctionCallExpression.x;
				case "getY":
					return FunctionCallExpression.y;
				case "getZ":
					return FunctionCallExpression.z;
			}
			throw new Error("Unknown function type: " + _functionCall);
		}
		//<--INumberExpression	
	}
}